package thirdpart.codec;
import com.alipay.remoting.serialization.SerializerManager;
import thirdpart.checksum.ByteCheckSum;

import java.io.Serializable;

public class BodyCodecImpl implements IBodyCodec {
    @Override
    public <T> byte[] serialize(T obj) throws Exception {
        /*jdk自带的序列化，性能并不高
          JSON：安全性不好
           自定义-Hessian2*/
        byte[] serializeBytes = SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(obj);
        return serializeBytes;
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) throws Exception {
        T  t = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(bytes, clazz.getName());
        return t;
    }
    static class A implements Serializable{
        public String a;
    }

    public static void main(String[] args) throws Exception {
     /*   A a = new A();
        a.a="test";
        byte[] bytes = new BodyCodecImpl().serialize(a);
        A a1 = new BodyCodecImpl().deserialize(bytes, A.class);
        System.out.println(a1.a);*/
        String a = "test";
        String b = "test1";
        String c = "test";
        byte ca = new ByteCheckSum().getCheckSum(a.getBytes());
        byte cb = new ByteCheckSum().getCheckSum(b.getBytes());
        byte cc = new ByteCheckSum().getCheckSum(c.getBytes());
        System.out.println(ca);
        System.out.println(cb);
        System.out.println(cc);


    }
}
